package com.etc.dao.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.sql.rowset.CachedRowSet;

import com.etc.dao.BussiteDao;
import com.etc.entity.Bussite;
import com.etc.util.DBUtil;
   /**
    * 中间站点增删改查具体实现
    * @author xst
    *
    */
public class BussiteDaoImpl implements BussiteDao {
	/**
	 * 查询所有车辆站点信息
	 */
	@Override
	public List<Bussite> queryBussites() {
		List<Bussite> list = new ArrayList<>();
		Bussite bussite = new Bussite();
		CachedRowSet crs = DBUtil.execQuery("select * from bussite");
		try {
			while (crs.next()) {
			int bs_id=crs.getInt(1);
			int b_id=crs.getInt(2);
			int s_id=crs.getInt(3);
			int s_location=crs.getInt(4);
			bussite=new Bussite(bs_id, b_id, s_id, s_location);
			list.add(bussite);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	/**
	 * 根据车辆编号查询车辆站点信息
	 */
	@Override
	public List<Bussite> queryBussitesByB_id(int b_id) {
		List<Bussite> list = new ArrayList<>();
		Bussite bussite = new Bussite();
		CachedRowSet crs = DBUtil.execQuery("select * from bussite where b_id=? order by s_location",b_id);
		try {
			while (crs.next()) {
			int bs_id=crs.getInt(1);
			int b_id1=crs.getInt(2);
			int s_id=crs.getInt(3);
			int s_location=crs.getInt(4);
			bussite=new Bussite(bs_id, b_id1, s_id, s_location);
			list.add(bussite);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	/**
	 * 增加车辆站点信息
	 */
	@Override
	public boolean addBussite(Bussite bussite) {
		// TODO Auto-generated method stub
		return DBUtil.executeUpdate("insert into bussite values(null,?,?,?)", bussite.getB_id(),bussite.getS_id(),bussite.getS_location());
	}
	/**
	 * 修改车辆站点信息
	 */
	@Override
	public boolean updatBussite(Bussite bussite) {
		// TODO Auto-generated method stub
		return DBUtil.executeUpdate("update bussite set b_id=?,s_id=?,s_location=? where bs_id=?", bussite.getB_id(),bussite.getS_id(),bussite.getS_location(),bussite.getBs_id());
	}
	/**
	 * 删除车辆站点信息
	 */
	@Override
	public boolean deleBussite(int bs_id) {
		// TODO Auto-generated method stub
		return DBUtil.executeUpdate("delete from bussite where bs_id=?", bs_id);
	}

}
